﻿@model  PagingDataSet<User>
@{
    Layout = "_Follow";
    Follow_SortBy sortBy = ViewData.Get<Follow_SortBy>("sortBy", Follow_SortBy.DateCreated_Desc);
    FollowService followService = new FollowService();
    long currentUserId = UserIdToUserNameDictionary.GetUserId(Url.SpaceKey());
    int followerCount = ViewData.Get<int>("followerCount", 0);
}
@section Aside{
    @Html.Action("_FollowUser_Menu", "Follow", new { menu = FollowUserMenu.MyFollowers })
}
<div class="tn-box tn-widget tn-widget-content tn-corner-all tnc-relation-fans">
    <div class="tn-box-content tn-widget-content tn-corner-all">
        <div class="tnc-relation-fans-wrap">
            <div class="tn-main-heading tn-border-gray tn-border-bottom">
                <h2>
                    粉丝</h2>
                <span class="tn-count tn-text-note">
                    @if (Model != null && followerCount > 0)
                    { @Html.Raw("(" + followerCount + ")") }</span>
            </div>
            <div class="tn-list-header tn-border-gray tn-border-bottom">
                <div class="tn-list-header-row">
                    <div class="tn-filter">
                        排序方式： <a href="@SiteUrls.Instance().ManageFollowers(Url.SpaceKey())"  
                    @if (sortBy == Follow_SortBy.DateCreated_Desc)
                    { @Html.Raw("class=\"tn-action tn-selected\"");
                    }
                    else
                    {@Html.Raw("class=\"tn-action\"");
                    }><span class="tn-action-text">收藏时间</span> </a><span class="tn-spacer tn-text-note">
                        |</span> <a href="@SiteUrls.Instance().ManageFollowers(Url.SpaceKey(), 2)" 
                     @if (sortBy == Follow_SortBy.FollowerCount_Desc)
                     { @Html.Raw("class=\"tn-action tn-selected\"");
                     }
                     else
                     {@Html.Raw("class=\"tn-action\"");
                     }><span class="tn-action-text">粉丝数</span> </a><span class="tn-spacer tn-text-note">|</span>
                        <a href="@SiteUrls.Instance().ManageFollowers(Url.SpaceKey(), 1)" 
                     @if (sortBy == Follow_SortBy.LastContent_Desc)
                     { @Html.Raw("class=\"tn-action tn-selected\"");
                     }
                     else
                     {@Html.Raw("class=\"tn-action\"");
                     }><span class="tn-action-text">最近更新的时间</span> </a>
                    </div>
                </div>
            </div>
            <div class="tnc-user-list">
                @if (Model != null && Model.TotalRecords > 0)
                {
                    <ul class="tn-list">
                        @foreach (var user in Model)
                        {
                            <li class="tn-list-item tn-helper-clearfix tn-border-gray tn-border-bottom tn-hover" id="Follower_@(user.UserId)">
                                <div class="tn-list-item-area-left">
                                    @Html.ShowUserAvatar(user.UserId, AvatarSizeType.Small, true, HyperLinkTarget._blank)
                                </div>
                                <div class="tn-list-item-area-main">
                                    <div class="tn-list-item-row">
                                        <a href="@SiteUrls.Instance().SpaceHome(user.UserName)"  class="tn-user-name" title="@user.DisplayName" target="_blank">@StringUtility.Trim(user.DisplayName, 20)</a>
                                        <div class="tnc-down-blkarrow tn-bg-deep tn-state-hidden" menu="#moreOptions3@(user.UserId)">
                                            <a href="#" class="tn-icon tn-smallicon-triangle-down"></a>
                                            <div class="tn-more-options tn-widget-content tn-border-gray" id="moreOptions3@(user.UserId)" style="display: none;">
                                                <ul class="tn-more-list">
                                                    <li>@Html.Link("发私信", SiteUrls.Instance()._CreateMessage(Url.SpaceKey(), toUserId: user.UserId), "发私信", htmlAttributes: new { id = "messageUserIdLink", plugin = "dialog", @class = "tn-item-link" })</li>
                                                    @if (followService.IsFollowed(currentUserId, user.UserId))
                                                    { 
                                                        <li data-followedUserId="@(user.UserId)">
                                                            @Html.Link("取消收藏", SiteUrls.Instance().CancelFollow(Url.SpaceKey(), user.UserId), "取消收藏", new { name = "Follow", status = "1", followedUserId = user.UserId, @class = "tn-item-link" })
                                                        </li>
                                                    }
                                                    else
                                                    {
                                                        <li data-followedUserId="@(user.UserId)">
                                                            @Html.Link("取消收藏", SiteUrls.Instance().CancelFollow(Url.SpaceKey(), user.UserId), "取消收藏", new { name = "Follow", status = "1", followedUserId = user.UserId, @class = "tn-item-link", style = "display: none;" })
                                                        </li>
                                                    }
                                                    <li>
                                                        @Html.Link("取消粉丝", SiteUrls.Instance().RemoveFollower(Url.SpaceKey(), user.UserId), "取消粉丝", new { @class = "tn-item-link", followerId = user.UserId, name = "RemoveFollower" })
                                                    </li>
                                                    <li>
                                                        @Html.Link("加入黑名单", SiteUrls.Instance().CreateStopedUser(Url.SpaceKey(), user.UserId), "加入黑名单", new { name = "StopUser", stopedUserId = user.UserId, @class = "tn-item-link" })
                                                    </li>
                                                    <li><a href="@Html.Raw(SiteUrls.Instance()._ImpeachReport(user.UserId, SiteUrls.Instance().SpaceHome(user.UserId), user.DisplayName))" rel="nofollow" plugin="dialog" class="tn-item-link">举报</a></li>
                                                </ul>
                                            </div>
                                        </div>
                                        <div class="tnc-relationship">
                                            <a id="createA" name="followed-follower-@user.UserId" class="tn-action tn-action-text-icon" href="@SiteUrls.Instance()._AddFollowedUser(Url.SpaceKey(), user.UserId)" plugin = "dialog" @if (followService.IsFollowed(currentUserId, user.UserId))
                                                                                                                                                                                                                                    {@Html.Raw("style=\"display: none;\"")}>
                                                <span class="tn-icon tn-smallicon-add"></span><span class="tn-action-text">加收藏</span>
                                            </a><span class="tn-explain-icon" id="eachSpan_@(user.UserId)"
                                             @if (!followService.IsFollowed(currentUserId, user.UserId))
                                             {@Html.Raw("style=\"display: none;\"")}><span class="tn-icon tn-smallicon-friendly">
                                             </span><span class="tn-icon-text">相互收藏</span> </span>
                                        </div>
                                    </div>
                                    @if (user.Profile != null)
                                    { 
                                        <div class="tn-list-item-row">
                                            <div class="tn-location">
                                                @if (user.Profile.Gender == GenderType.FeMale)
                                                {@Html.Icon(IconTypes.SmallFemale, "女")}
                                                @if (user.Profile.Gender == GenderType.Male)
                                                {@Html.Icon(IconTypes.SmallMale, "男")}
                                                @Formatter.FormatArea(user.Profile.NowAreaCode, true)
                                            </div>
                                        </div>
                                    }
                                    <div class="tn-list-item-row tnc-usernums">
                                        <span>收藏 <a href="@SiteUrls.Instance().ListFollowedUsers(user.UserName)"><strong>@user.FollowedCount</strong></a></span>
                                        <span class="tn-spacer tn-text-note">|</span> <span>粉丝 <a href="@SiteUrls.Instance().ListFollowers(user.UserName)" >
                                            <strong>@user.FollowerCount</strong></a></span> <span class="tn-spacer tn-text-note">
                                                |</span> <span>内容 <strong>@user.ContentCount</strong></span>
                                    </div>
                                    @if (user.Profile != null && !string.IsNullOrEmpty(user.Profile.Introduction.Trim()))
                                    {
                                        <div class="tn-list-item-row">
                                            简介：
                                            @HtmlUtility.TrimHtml(user.Profile.Introduction,100)
                                        </div>
                                    }
                                </div>
                            </li>
                        }
                    </ul>
                    <div class="tn-pagination">
                        @Html.PagingButton(Model, PaginationMode.NumericNextPrevious, 5)
                    </div>
                }
                else
                { 
                    <div class="tn-no-data">
                        尚未有粉丝</div>
                }
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $(".tn-more-options .tn-item-link").hover(function () {
            $(this).addClass("tn-bg-gray");
        }, function () {
            $(this).removeClass("tn-bg-gray");
        });
        $("tr span[menu]").menuButton({
            buttonHoverClass: 'ui-widget-content tn-action-hover'
        });

    });

    $("a[name='RemoveFollower']").click(function (e) {
        e.preventDefault();
        var $this = $(this);
        var followerId = $this.attr('followerId');

        art.dialog.confirm('确定要取消粉丝吗？&nbsp;&nbsp;', function () {
            $.ajax({
                type: "Post",
                url: $this.attr("href"),
                success: function (msg) {
                    $("#Follower_" + followerId).fadeOut();
                },
                error: function () {
                    art.dialog.tips("取消失败", 1.5, -1);
                }
            });
        });
    });



    $("a[name='StopUser']").click(function (e) {
        e.preventDefault();
        $this = $(this);
        var stopedUserId = $this.attr("stopedUserId");

        art.dialog.confirm('加入黑名单会解除关系，确定要加入黑名单吗？&nbsp;&nbsp;', function () {
            $.ajax({
                type: "Get",
                url: $this.attr("href"),
                success: function (msg) {
                    $("#Follower_" + stopedUserId).fadeOut();
                },
                error: function () {
                    art.dialog.tips("加入黑名单失败", 1.5, -1);
                }
            });
        });
    });

    $("a[name='Follow']").click(function (e) {
        e.preventDefault();
        var $this = $(this);
        var followedUserId = $this.attr('followedUserId');

        art.dialog.confirm('确定要取消收藏用户吗？&nbsp;&nbsp;', function () {
            $.ajax({
                type: "Post",
                url: $this.attr("href"),
                success: function (msg) {
                    $("#eachSpan_" + followedUserId).hide();
                    $("a[followedUserId=" + followedUserId + "]").hide();
                    $("a[name=\'followed-follower-" + msg.Data.followId + "\']").show();

                },
                error: function () {
                    art.dialog.tips("删除失败", 1.5, -1);
                }
            });
        });


    });
</script>
